package com.haiwei.poi.excel.common;

import com.haiwei.poi.word.common.HaiweiWeakTempFile;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;

import java.io.File;

/**
 * HaiweiWeakTempFile单元测试类.
 *
 * @date: 2022-06-24
 * @version: 1.0
 * @author: karry@haiwei.com
 */
@Slf4j
public class HaiweiWeakTempFileTester {
    
    @Test
    public void createTempFileTest() throws Exception {
        String path = "";
        {
            File file = HaiweiWeakTempFile.createTempFile("test.temp.",".txt");
            path = file.getAbsolutePath();
            log.info("temp file path : " + path);
        }
        Thread.sleep(1 * 1000l);
        log.info("start to gc ...");
        System.gc();
        Assert.assertTrue("临时文件删除过早,path:" + path ,new File(path).exists());
        Thread.sleep(1 * 1000l);
        Assert.assertFalse("临时文件删除过早,path:" + path,new File(path).exists());
        log.info("createTempFile end ...");
    }
    
}
